<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>10. Funktionen &mdash; PowerShell fuer Systemintegratoren</title>
    
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/translations.js"></script>
    <link rel="top" title="PowerShell fuer Systemintegratoren" href="index.html" />
    <link rel="next" title="11. Pipeline" href="powershell_pipeline.html" />
    <link rel="prev" title="9. Diagramme der strukturierten Programmierung" href="powershell_struktogramm.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="Allgemeiner Index"
             accesskey="I">Index</a></li>
        <li class="right" >
          <a href="powershell_pipeline.html" title="11. Pipeline"
             accesskey="N">weiter</a> |</li>
        <li class="right" >
          <a href="powershell_struktogramm.html" title="9. Diagramme der strukturierten Programmierung"
             accesskey="P">zurück</a> |</li>
        <li><a href="index.html">PS4SYS</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/PowerShell_icon_small.png" alt="Logo"/>
            </a></p>
  <h3><a href="index.html">Inhalt</a></h3>
  <ul>
<li><a class="reference internal" href="#">10. Funktionen</a><ul>
<li><a class="reference internal" href="#grundsatzlicher-aufbau">10.1. Grundsätzlicher Aufbau</a></li>
<li><a class="reference internal" href="#ubergabe-von-argumenten">10.2. Übergabe von Argumenten</a></li>
<li><a class="reference internal" href="#ruckgabewerte">10.3. Rückgabewerte</a></li>
<li><a class="reference internal" href="#ablaufsteuerung">10.4. Ablaufsteuerung</a></li>
<li><a class="reference internal" href="#return-statement">10.5. Return Statement</a></li>
<li><a class="reference internal" href="#textausgeben-verhindern">10.6. Textausgeben verhindern</a></li>
<li><a class="reference internal" href="#inline-help-von-funktionen">10.7. Inline-Help von Funktionen</a></li>
<li><a class="reference internal" href="#groszeres-beispiel-bzgl-funktionen">10.8. Größeres Beispiel bzgl. Funktionen</a></li>
<li><a class="reference internal" href="#benutzung-von-wmi">10.9. Benutzung von WMI</a></li>
<li><a class="reference internal" href="#erweiterte-parameter">10.10. Erweiterte Parameter</a></li>
<li><a class="reference internal" href="#funktionen-in-profilen">10.11. Funktionen in Profilen</a></li>
<li><a class="reference internal" href="#urls">10.12. Urls</a></li>
</ul>
</li>
</ul>

  <h4>Vorheriges Thema</h4>
  <p class="topless"><a href="powershell_struktogramm.html"
                        title="vorheriges Kapitel">9. Diagramme der strukturierten Programmierung</a></p>
  <h4>Nächstes Thema</h4>
  <p class="topless"><a href="powershell_pipeline.html"
                        title="nächstes Kapitel">11. Pipeline</a></p>
  <h3>Diese Seite</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/powershell_funktionen.txt"
           rel="nofollow">Quelltext anzeigen</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Schnellsuche</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Los" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Geben Sie Suchbegriffe oder einen Modul-, Klassen- oder Funktionsnamen ein.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="funktionen">
<h1>10. Funktionen<a class="headerlink" href="#funktionen" title="Permalink zu dieser Überschrift">¶</a></h1>
<p>Häufig ist es sinnvoll, seinen Quellcode in abgeschlossenen Strukturen zu definieren. Die rein sequenzielle Abfolge wird ersetzt durch den Aufruf von Programmcontainern, die eine gewisse Funktionalität bereitstellen. Auf diese Funktionalität kann dann innerhalb des Skriptes immer wieder zugegriffen werden.</p>
<p>Folgende Elemente werden beinhaltet:</p>
<ul class="simple">
<li>Funktionskopf (Signatur)</li>
<li>Rückgabewerte</li>
<li>Parameterübergabe</li>
</ul>
<div class="section" id="grundsatzlicher-aufbau">
<h2>10.1. Grundsätzlicher Aufbau<a class="headerlink" href="#grundsatzlicher-aufbau" title="Permalink zu dieser Überschrift">¶</a></h2>
<p id="index-0">Funktionen sind selbst definierte Kommandos, die im Prinzip drei Aufgaben haben:</p>
<ul class="simple">
<li>Shorthand: Abkürzungen für einfache Befehle zur Arbeitserleichterung</li>
<li>Combining: Funktionen können Arbeit erleichtern, indem Sie mehrere Arbeitsschritte zusammenfassen können</li>
<li>Kapselung und Erweiterung:</li>
</ul>
<div class="sidebar">
<p class="first sidebar-title">Tafelbild</p>
<p class="last">Aufbau einer Funktion</p>
</div>
<a class="reference external image-reference" href="_images/notizzettel.png"><img alt="alternate text" class="align-left" src="_images/notizzettel.png" style="width: 50px;" /></a>
<p>Der grundlegende Aufbau einer Funktion ist immer gleich.</p>
<p>Nach dem Funktion-Statement folgt der Name der Funktion und anschließend der Powershell-Codeblock in geschweiften Klammern. Ein Beispiel:</p>
<div class="highlight-sh"><div class="highlight"><pre>Function Cd.. <span class="o">{</span> Cd .. <span class="o">}</span>
Cd..

<span class="c">#Für immer wiederkehrende Aufgaben</span>

Function myPing <span class="o">{</span> ping.exe -w 100 -n 1 10.10.10.10 <span class="o">}</span>
myPing
Pinging 10.10.10.10 with 32 bytes of data:
Reply from 88.70.64.1: destination host unreachable.

<span class="c">#mit einem Argument</span>
Function myPing <span class="o">{</span> ping.exe -w 100 -n 1 <span class="nv">$args</span> <span class="o">}</span>
myPing www.microsoft.com
Pinging lb1.www.ms.akadns.net <span class="o">[</span>207.46.193.254<span class="o">]</span> with 32 bytes of data:
Request timed out.
Ping statistics <span class="k">for </span>207.46.193.254:
Packets: <span class="nv">Sent</span> <span class="o">=</span> 1, <span class="nv">Received</span> <span class="o">=</span> 0, <span class="nv">Lost</span> <span class="o">=</span> 1 <span class="o">(</span>100% Loss<span class="o">)</span>,
</pre></div>
</div>
<p>Gerade bei längeren Funktionen kann die Eingabe innerhalb einer Zeile etwas umständlich sein. Eingaben können in <strong>Powershell</strong> allerdings über mehrere Zeilen gehen. Dies erreicht man durch Drücken von Return, wenn die jeweils aktuelle Zeile noch nicht fertig geschreiben ist.</p>
<img alt="_images/funktionen_auf_konsole.jpg" src="_images/funktionen_auf_konsole.jpg" />
<p>Spätestens jetzt wird der Einsatz eines Editors bzw. der grafischen Version der <strong>Powershell</strong> überlegenswert.</p>
<p>Eine Darstellung des gesamten Funktion kann man mit folgender Zeile erreichen</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$function</span>:NextFreeDrive
</pre></div>
</div>
<img alt="_images/function_nextfreedrive.jpg" src="_images/function_nextfreedrive.jpg" />
<p>Die Ausgabe einer Funktion in eine Textdatei kann man z.B. mit dem Out-File-Commandlet erreichen</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$function</span>:NextFreeDrive | Out-File -Encoding utf8 nextfreedrive.ps1
notepad .<span class="se">\n</span>extfreedrive.ps1
</pre></div>
</div>
<img alt="_images/function_nextfreedrive_script.jpg" src="_images/function_nextfreedrive_script.jpg" />
</div>
<div class="section" id="ubergabe-von-argumenten">
<span id="index-1"></span><h2>10.2. Übergabe von Argumenten<a class="headerlink" href="#ubergabe-von-argumenten" title="Permalink zu dieser Überschrift">¶</a></h2>
<div class="sidebar">
<p class="first sidebar-title">Tafelbild</p>
<p class="last">Funktionen und Argumente</p>
</div>
<a class="reference external image-reference" href="_images/notizzettel.png"><img alt="alternate text" class="align-left" src="_images/notizzettel.png" style="width: 50px;" /></a>
<p>Häufig will man einer Funktion Informationen mit übergeben, die diese dann weiterverarbeiten soll. Dies wird mit Hilfe von sog. <strong>Argumenten</strong> bewerkstelligt. Es gibt 4 verschiedene Arten der Argumentübergabe</p>
<dl class="docutils" id="index-2">
<dt><strong>Arbitrary arguments:</strong></dt>
<dd><p class="first">die $args variable (Array) beinhaltet alle Parameter, die einer Funktion übergeben werden. Damit ist sie eine gute Lösung, wenn eine flexible Anzahl von Parametern übergeben werden soll.</p>
<div class="last highlight-sh"><div class="highlight"><pre><span class="k">function </span>add<span class="o">()</span>
<span class="o">{</span>
        <span class="nv">$i</span> <span class="o">=</span> 0
        foreach<span class="o">(</span><span class="nv">$_</span> in <span class="nv">$args</span><span class="o">)</span>
        <span class="o">{</span>
                <span class="nv">$i</span> <span class="o">=</span> <span class="nv">$i</span> +  <span class="nv">$_</span>
        <span class="o">}</span>

        Write-Host <span class="nv">$i</span>
<span class="o">}</span>
</pre></div>
</div>
</dd>
</dl>
<dl class="docutils" id="index-3">
<dt><strong>Named arguments:</strong></dt>
<dd><p class="first">Eine Funktion kann auch pro Parameter einen Namen vergeben. Damit ist die Reihenfolge der Parameter beliebig, weil Sie über den Namen aufgelöst werden.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="k">function </span>add1<span class="o">(</span><span class="nv">$value1</span>, <span class="nv">$value2</span><span class="o">)</span>
<span class="o">{</span>
        Write-Host <span class="o">(</span><span class="nv">$value1</span> + <span class="nv">$value2</span><span class="o">)</span>
<span class="o">}</span>
add1 -value2 10 -value1 10
</pre></div>
</div>
<img alt="_images/function_named_parameters.png" class="last" src="_images/function_named_parameters.png" />
</dd>
</dl>
<dl class="docutils" id="index-4">
<dt><strong>Predefined arguments:</strong></dt>
<dd><p class="first">Parameter können mit default-Werten versehen sein. Falls der Benutzer keine eigenen Werte übergibt, werden die default-Werte genommen.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="k">function </span>add2<span class="o">(</span><span class="nv">$value1</span><span class="o">=</span>10, <span class="nv">$value2</span><span class="o">=</span>20<span class="o">)</span>
<span class="o">{</span>
        Write-Host <span class="o">(</span><span class="nv">$value1</span> + <span class="nv">$value2</span><span class="o">)</span>
<span class="o">}</span>

add -value2 10 -value1 10
</pre></div>
</div>
<img alt="_images/function_default_value.png" class="last" src="_images/function_default_value.png" />
</dd>
</dl>
<dl class="docutils" id="index-5">
<dt><strong>Typed arguments:</strong></dt>
<dd><p class="first">Parameter können mit einem bestimmten Datentyp definiert werden, um sicherzustellen, dass nur die Argumente aus &#8220;richtigen&#8221; Datentypen bestehen.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="k">function </span>add<span class="o">([</span>int<span class="o">]</span> <span class="nv">$value1</span>, <span class="o">[</span>int<span class="o">]</span> <span class="nv">$value2</span><span class="o">)</span>
<span class="o">{</span>
        <span class="nv">$value1</span> + <span class="nv">$value2</span>
<span class="o">}</span>
</pre></div>
</div>
<img alt="_images/function_type_misinterpretation.png" class="last" src="_images/function_type_misinterpretation.png" />
</dd>
</dl>
<dl class="docutils" id="index-6">
<dt><strong>Special argument types:</strong></dt>
<dd><p class="first">Neben herkömmlichen Datentypen können Parameter auch wie ein <strong>switch</strong>-Befehl funktionieren. Wenn der Parametername übergeben wird, dann hat der Parameter den Wert $true, ansonsten $false</p>
<div class="last highlight-sh"><div class="highlight"><pre><span class="k">function </span>add<span class="o">(</span><span class="nv">$wert1</span>, <span class="nv">$wert2</span>, <span class="o">[</span>switch<span class="o">]</span><span class="nv">$help</span>
<span class="o">{</span>
        <span class="k">if</span><span class="o">(</span><span class="nv">$help</span><span class="o">)</span>
        <span class="o">{</span>
                Write-Host <span class="s2">&quot;Hilfe ausgeben&quot;</span>
        <span class="o">}</span>
<span class="o">}</span>

add -help
</pre></div>
</div>
</dd>
</dl>
</div>
<div class="section" id="ruckgabewerte">
<span id="index-7"></span><h2>10.3. Rückgabewerte<a class="headerlink" href="#ruckgabewerte" title="Permalink zu dieser Überschrift">¶</a></h2>
<p>In <strong>Powershell</strong> geben Funktionen nie nur einen Wert zurück sondern immer alles. Wenn man die Funktion lediglich aufruft, gibt die Funktion die Ausgabe über die Konsole aus. Die Ausgabe kann aber auch in einer Variablen gefangen werden.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="k">function </span>add3<span class="o">(</span><span class="nv">$value1</span><span class="o">=</span>10, <span class="nv">$value2</span><span class="o">=</span>20<span class="o">)</span>
<span class="o">{</span>
        <span class="nv">$value1</span> + <span class="nv">$value2</span>
<span class="o">}</span>

<span class="nv">$result</span> <span class="o">=</span> add3 -value1 10 -value2 10
<span class="nv">$result</span>
</pre></div>
</div>
<img alt="_images/function_returnvalue.png" src="_images/function_returnvalue.png" />
<p><strong>Solange die Funktion nur einen Wert zurückliefert, ist der Rückgabetyp quasi eine Variable. Falls mehrere Ausgaben erfolgen würden, wird die Ausgabe in einen Array gekapselt. Dieser kann von der aufrufenden Seite aus beliebig angepackt werden.</strong></p>
<div class="highlight-sh"><div class="highlight"><pre><span class="k">function </span>VAT<span class="o">([</span>double<span class="o">]</span><span class="nv">$amount</span><span class="o">=</span>0<span class="o">)</span>
<span class="o">{</span>
        <span class="nv">$amount</span> * 0.19
<span class="o">}</span>
<span class="c"># An interactively invoked function</span>
<span class="c"># output results in the console:</span>
VAT 130.67
24.8273
<span class="c"># But the result of the function can</span>
<span class="c"># also be assign to a variable:</span>
<span class="nv">$result</span> <span class="o">=</span> VAT 130.67
<span class="nv">$result</span>
24.8273
<span class="c"># The result is a single number value</span>
<span class="c"># of the &quot;double&quot; type:</span>
<span class="nv">$result</span>.GetType<span class="o">()</span>.Name
Double

Function VAT<span class="o">([</span>double<span class="o">]</span><span class="nv">$amount</span><span class="o">=</span>0<span class="o">)</span>
<span class="o">{</span>
        <span class="nv">$factor</span> <span class="o">=</span> 0.19
        <span class="nv">$total</span> <span class="o">=</span> <span class="nv">$amount</span> * <span class="nv">$factor</span>
        <span class="s2">&quot;Value added tax {0:C}&quot;</span> -f <span class="nv">$total</span>
        <span class="s2">&quot;Value added tax rate: {0:P}&quot;</span> -f <span class="nv">$factor</span>
<span class="o">}</span>

The <span class="k">function </span>returns two results:
VAT 130.67
Value added tax <span class="nv">$24</span>.83
Value added tax rate: 19.00%
<span class="c"># All results are stored in a single variable:</span>
<span class="nv">$result</span> <span class="o">=</span> VAT 130.67
<span class="nv">$result</span>
Value added tax <span class="nv">$24</span>.83
Value added tax rate: 19.00%
<span class="c"># Several results are automatically stored in an array:</span>
<span class="nv">$result</span>.GetType<span class="o">()</span>.Name
Object<span class="o">[]</span>
<span class="c"># You can get each separate result of the</span>
<span class="c"># function by using the index number:</span>
<span class="nv">$result</span><span class="o">[</span>0<span class="o">]</span>
Value added tax <span class="nv">$24</span>.83
<span class="c"># The data type of the respective array element</span>
<span class="c"># corresponds to the included data:</span>
<span class="nv">$result</span><span class="o">[</span>0<span class="o">]</span>.GetType<span class="o">()</span>.Name
String
</pre></div>
</div>
<img alt="_images/function_return_array.png" src="_images/function_return_array.png" />
</div>
<div class="section" id="ablaufsteuerung">
<span id="index-8"></span><h2>10.4. Ablaufsteuerung<a class="headerlink" href="#ablaufsteuerung" title="Permalink zu dieser Überschrift">¶</a></h2>
<div class="sidebar">
<p class="first sidebar-title">Tafelbild</p>
<p class="last">Funktionen und Ablaufsteuerung</p>
</div>
<a class="reference external image-reference" href="_images/notizzettel.png"><img alt="alternate text" class="align-left" src="_images/notizzettel.png" style="width: 50px;" /></a>
<p>Das Aufteilen des Skriptes in Funktionen teilt den Quellcode in zwei Bereiche auf, nämlich den</p>
<ul class="simple">
<li>der Funktionalität und</li>
<li>der Ablaufsteuerung</li>
</ul>
<p>Da Funktionen zunächst innerhalb des Skriptes überhaupt keine Wirkung besitzen, werden sie erst durch die restlichen Codeteile, der Ablaufsteuerung, zum &#8220;Leben erweckt&#8221;. Die Verbindung zwischen beiden Teilen erfolgt durch die</p>
<ul class="simple">
<li>hereingereichten Parameter und die</li>
<li>zurückgegebenen Ergebnisse.</li>
</ul>
</div>
<div class="section" id="return-statement">
<span id="index-9"></span><h2>10.5. Return Statement<a class="headerlink" href="#return-statement" title="Permalink zu dieser Überschrift">¶</a></h2>
<p>Das RETURN-Statement hat in der <strong>Powershell</strong> nicht die selbe Bedeutung wie in anderen Programmiersprachen, da Funktionen immer alles zurückgeben. Es wurde dennoch implementiert, vor allem aus 2 Gründen:</p>
<dl class="docutils">
<dt>Style:</dt>
<dd>Man folgte damit den Vorgaben anderer Programmiersprachen, die ebenfalls ein RETURN-Statement haben</dd>
<dt>Beenden einer Funktion:</dt>
<dd>Return beenedet eine Funktion; alle Ausgaben unterhalb des RETURN-Statements würden von der Funktion nicht zurückgegeben werden.</dd>
</dl>
<div class="highlight-sh"><div class="highlight"><pre>Function Add<span class="o">([</span>double<span class="o">]</span><span class="nv">$value1</span>, <span class="o">[</span>double<span class="o">]</span><span class="nv">$value2</span><span class="o">)</span>
<span class="o">{</span>
        <span class="c"># This time the function returns a whole</span>
        <span class="c"># series of oddly assorted results:</span>
        <span class="s2">&quot;Here the result follows:&quot;</span>
        1
        2
        3
        <span class="c"># Return also returns a further result:</span>
        <span class="k">return</span> <span class="nv">$value1</span> + <span class="nv">$value2</span>

        <span class="c"># This statement will no longer be executed</span>
        <span class="c"># because the function will exit when return is used:</span>
        <span class="s2">&quot;Another text&quot;</span>
<span class="o">}</span>
Add 1 6
Here the result follows:
1
2
3
7
<span class="nv">$result</span> <span class="o">=</span> Add 1 6
<span class="nv">$result</span>
Here the result follows:
1
2
3
7
</pre></div>
</div>
</div>
<div class="section" id="textausgeben-verhindern">
<h2>10.6. Textausgeben verhindern<a class="headerlink" href="#textausgeben-verhindern" title="Permalink zu dieser Überschrift">¶</a></h2>
<p>Häufig hat man bestimmte Ausgaben nur für Kontrollzwecke bzw. Debug-Ausgaben in eine Funktion integriert. Im Produktiveinsatz will man diese Ausgaben nicht sehen und benötigt sie auch nicht.</p>
<p>Folgendes Beispiel zeigt mögliche Alternativen:</p>
<div class="highlight-sh"><div class="highlight"><pre>Function Test
<span class="o">{</span>
        <span class="s2">&quot;Calculation will be performed&quot;</span>
        <span class="nv">$a</span> <span class="o">=</span> 12 * 10
        <span class="s2">&quot;Result will be emitted&quot;</span>
        <span class="s2">&quot;Result is: $a&quot;</span>
        <span class="s2">&quot;Done&quot;</span>
<span class="o">}</span>
Test
Calculation will be performed
Result will be emitted
Result is: 120
Done

<span class="nv">$result</span> <span class="o">=</span> Test
<span class="nv">$result</span>
</pre></div>
</div>
<p>Für diesen Zweck gibt es mehrere Möglichkeiten.</p>
<dl class="docutils" id="index-10">
<dt>Write-Host benutzen:</dt>
<dd><p class="first">Das Cmdlet Write-Host gibt die Ausgabe sofort an die Konsole weiter</p>
<div class="last highlight-sh"><div class="highlight"><pre>Function Test
<span class="o">{</span>
        Write-Host <span class="s2">&quot;Calculation will be performed&quot;</span>
        <span class="nv">$a</span> <span class="o">=</span> 12 * 10
        Write-Host <span class="s2">&quot;Result will be emitted&quot;</span>
        <span class="s2">&quot;Result is: $a&quot;</span>
        Write-Host <span class="s2">&quot;Done&quot;</span>
<span class="o">}</span>
<span class="c"># This time your debugging reports will already</span>
<span class="c"># be output when the function is executed:</span>
<span class="nv">$result</span> <span class="o">=</span> <span class="nb">test</span>
Calculation will be performed
Result will be emitted
Done
<span class="c"># The result will no long include your debugging reports:</span>
<span class="nv">$result</span>
Result is: 120
</pre></div>
</div>
</dd>
</dl>
<dl class="docutils" id="index-11">
<dt>Debug-Ausgabe benutzen</dt>
<dd><p class="first">Mit Hilfe des Write-Debug-Cmdlets können Ausgaben nur zu Debug-Zwecken ausgegeben werden. Voraussetzung st allerdings, dass man die globale Variabel $DebugPrefeence auf &#8220;SilentlyContinue&#8221; stellt</p>
<div class="last highlight-sh"><div class="highlight"><pre>Function Test
<span class="o">{</span>
        Write-Debug <span class="s2">&quot;Calculation will be performed&quot;</span>
        <span class="nv">$a</span> <span class="o">=</span> 12 * 10
        Write-Debug <span class="s2">&quot;Result will be emitted&quot;</span>
        <span class="s2">&quot;Result is: $a&quot;</span>
        Write-Debug <span class="s2">&quot;Done&quot;</span>
<span class="o">}</span>
<span class="c"># Debugging reports will remain completely</span>
<span class="c"># invisible in the production environment:</span>
<span class="nv">$result</span> <span class="o">=</span> Test
<span class="c"># If you would like to debug your function,</span>
<span class="c"># turn on reporting:</span>
<span class="nv">$DebugPreference</span> <span class="o">=</span> <span class="s2">&quot;Continue&quot;</span>
<span class="c"># Your debugging reports will now be output</span>
<span class="c"># with the &quot;DEBUG:&quot; prefix and output in yellow:</span>
<span class="nv">$result</span> <span class="o">=</span> Test
DEBUG: Calculation will be performed
DEBUG: Result will be emitted
DEBUG: Done
<span class="c"># They are not contained in the result:</span>
<span class="nv">$result</span>
Result is: 120
<span class="c"># Everything is running the way you wish;</span>
<span class="c"># turn off debugging:</span>
<span class="nv">$DebugPreference</span> <span class="o">=</span> <span class="s2">&quot;SilentlyContinue&quot;</span>
<span class="nv">$result</span> <span class="o">=</span> Test
</pre></div>
</div>
</dd>
</dl>
<dl class="docutils" id="index-12">
<dt>Fehlermeldungen unterdrücken:</dt>
<dd><p class="first">Fehlermeldungen werden normalerweise immer sofort ausgegeben, was natürlich den Ablauf eines Skriptes stören kann. Auch hier gibt es wieder eine globale Variable, welches die Ausgabe von Fehlermeldungen steuern kann.</p>
<div class="last highlight-sh"><div class="highlight"><pre>Function Test
<span class="o">{</span>
        <span class="c"># Suppress all error messages from now on:</span>
        <span class="nv">$ErrorActionPreference</span> <span class="o">=</span> <span class="s2">&quot;SilentlyContinue&quot;</span>
        Stop-Process -name <span class="s2">&quot;Unavailableprocess&quot;</span>
        <span class="c"># Immediately begin outputting all error messages again:</span>
        <span class="nv">$ErrorActionPreference</span> <span class="o">=</span> <span class="s2">&quot;Continue&quot;</span>
        1/<span class="nv">$null</span>
<span class="o">}</span>
<span class="c"># Error messages will be suppressed in certain</span>
<span class="c"># areas but not in others:</span>
<span class="nv">$result</span> <span class="o">=</span> Test
</pre></div>
</div>
</dd>
</dl>
</div>
<div class="section" id="inline-help-von-funktionen">
<span id="index-13"></span><h2>10.7. Inline-Help von Funktionen<a class="headerlink" href="#inline-help-von-funktionen" title="Permalink zu dieser Überschrift">¶</a></h2>
<p>Um den Nutzer einer Funktion auch innerhalb der Powershell mit Informationen über die Funktion versorgen zu können, kann man sowohl Funktionen als auch das ganze Skript mit einer sog. <strong>Inline-Help</strong> ausstatten. Im Grunde handelt es sich dabei um eine Abfolge von Kommentarzeilen, die mit bestimmten Schlüsselworten versehen worden sind.</p>
<p>Details der Anwendung gibt es unter <a class="reference external" href="http://technet.microsoft.com/en-us/library/dd819489.aspx">http://technet.microsoft.com/en-us/library/dd819489.aspx</a></p>
<div class="highlight-sh"><div class="highlight"><pre>&lt;<span class="c">#</span>
 .SYNOPSIS
         Dieses Skript gibt eine Liste der nicht funktionierenden
         Hardware aus mit Hilfe von WMI.
 .DESCRIPTION
         Per WMI werden zunächst die Systemdetails ermittelt
         und dann die Hardware mit Fehlern.
 .NOTES
         File Name  : Get-BrokenHardware.ps1
         Author     : Karl Steinam - teetscher
         Requires   : PowerShell Version 2.0
 .LINK
         Siehe auch:
                 http://www.meineFirma.de
 .EXAMPLE
         PSH <span class="o">[</span>C:<span class="se">\f</span>oo<span class="o">]</span>: Get-BrokenHardware.ps1
         Computer Details:
         Manufacturer: Dell Inc.
         Model:        Precision WorkStation T7400
         Service Tag:  6Y84C3J

         Hardware thats not working list
         Description:  WD My Book Device USB Device
         Device ID:    USBSTOR<span class="se">\O</span>THER&amp;VEN_WD&amp;P<span class="se">\7</span>0332&amp;1
         Error ID:     28
 <span class="c">#&gt;</span>

 <span class="c"># Display Computer details</span>
 <span class="s2">&quot;Computer Details:&quot;</span>
 <span class="nv">$comp</span> <span class="o">=</span> gwmi Win32_ComputerSystem
 <span class="s2">&quot;Manufacturer: {0}&quot;</span> -f <span class="nv">$comp</span>.Manufacturer
 <span class="s2">&quot;Model:        {0}&quot;</span> -f <span class="nv">$comp</span>.Model
 <span class="nv">$computer2</span> <span class="o">=</span> Get-WmiObject Win32_ComputerSystemProduct
 <span class="s2">&quot;Service Tag:  {0}&quot;</span> -f <span class="nv">$computer2</span>.IdentifyingNumber
 <span class="s2">&quot;&quot;</span>

 <span class="c">#Get hardware that is errored</span>
 <span class="s2">&quot;Hardware that&#39;s not working list&quot;</span>
 <span class="nv">$broken</span> <span class="o">=</span> Get-WmiObject Win32_PnPEntity | where <span class="sb">`</span>
 <span class="o">{</span><span class="nv">$_</span>.ConfigManagerErrorCode -ne 0<span class="o">}</span> <span class="sb">`</span>

 <span class="c">#Display broken hardware</span>
 foreach <span class="o">(</span><span class="nv">$obj</span> in <span class="nv">$broken</span><span class="o">){</span>
 <span class="s2">&quot;Description:  {0}&quot;</span> -f  <span class="nv">$obj</span>.Description
 <span class="s2">&quot;Device ID:    {0}&quot;</span> -f  <span class="nv">$obj</span>.DeviceID
 <span class="s2">&quot;Error ID:     {0}&quot;</span> -f  <span class="nv">$obj</span>.ConfigManagerErrorCode
 <span class="s2">&quot;&quot;</span>
 <span class="o">}</span>
</pre></div>
</div>
<img alt="_images/inline-help_1.jpg" src="_images/inline-help_1.jpg" />
<img alt="_images/inline-help_2.jpg" src="_images/inline-help_2.jpg" />
<p>Das nächste Beispiel fügt einer Funktion eine Inline-Help hinzu.</p>
<div class="highlight-sh"><div class="highlight"><pre>&lt;<span class="c">#</span>
        .SYNOPSIS
        Adds a file name extension to a supplied name.

        .DESCRIPTION
        Adds a file name extension to a supplied name.
        Takes any strings <span class="k">for </span>the file name or extension.

        .PARAMETER Name
        Specifies the file name.

        .PARAMETER Extension
        Specifies the extension. <span class="s2">&quot;Txt&quot;</span> is the default.

        .INPUTS
        None. You cannot pipe objects to Add-Extension.

        .OUTPUTS
        System.String. Add-Extension returns a string
        with the extension or file name.

        .EXAMPLE
        C:<span class="se">\P</span>S&gt; extension -name <span class="s2">&quot;File&quot;</span>
        File.txt

        .EXAMPLE
        C:<span class="se">\P</span>S&gt; extension <span class="s2">&quot;File&quot;</span> <span class="s2">&quot;doc&quot;</span>
        File.doc

        .LINK
        http://www.fabrikam.com/extension.html

        .LINK
        Set-Item
        <span class="c">#&gt;</span>
<span class="k">function </span>Add-Extension2
<span class="o">{</span>
        param <span class="o">([</span>string<span class="o">]</span><span class="nv">$Name</span>,<span class="o">[</span>string<span class="o">]</span><span class="nv">$Extension</span> <span class="o">=</span> <span class="s2">&quot;txt&quot;</span><span class="o">)</span>
        <span class="nv">$name</span> <span class="o">=</span> <span class="nv">$name</span> + <span class="s2">&quot;.&quot;</span> + <span class="nv">$extension</span>
        <span class="nv">$name</span>
<span class="o">}</span>
</pre></div>
</div>
<p>Je nach Laune kann die Inline-Help auch innerhalb der Funktion geschrieben werden.</p>
</div>
<div class="section" id="groszeres-beispiel-bzgl-funktionen">
<h2>10.8. Größeres Beispiel bzgl. Funktionen<a class="headerlink" href="#groszeres-beispiel-bzgl-funktionen" title="Permalink zu dieser Überschrift">¶</a></h2>
<p>Siehe:</p>
<p><a class="reference external" href="http://www.powershellpro.com/powershell-tutorial-introduction/powershell-scripting-with-wmi/">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-scripting-with-wmi/</a></p>
<p><a class="reference external" href="http://www.powershellpro.com/computernames-activedirectory/149/">http://www.powershellpro.com/computernames-activedirectory/149/</a></p>
<p><a class="reference external" href="http://www.computerperformance.co.uk/powershell/powershell_example_basic.htm#Example_4:_PowerShell_Real-life_Task">http://www.computerperformance.co.uk/powershell/powershell_example_basic.htm#Example_4:_PowerShell_Real-life_Task</a></p>
<p><a class="reference external" href="http://www.powershellpro.com/powershell-tutorial-introduction/powershell-scripting-with-wmi/">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-scripting-with-wmi/</a></p>
<p><a class="reference external" href="http://technobeans.wordpress.com/2010/11/25/powershell-getting-inventory-details/">http://technobeans.wordpress.com/2010/11/25/powershell-getting-inventory-details/</a></p>
<p><strong>Vorausetzung:</strong></p>
<p>Installiertes CIM-Studio zur Abfrage des WMI</p>
<p>Im folgenden Beispiel sollen mit Hilfe von WMI verschiedene Informationen des lokalen Rechners abgerufen werden. In weiteren Schritten wird die Suche auf beliebige Rechner ausgeweitet. Im letzten Schritt werden Informationen des ActiveDirectory genutzt, um eine komfortable Liste der Rechner zu erhalten.</p>
<p><strong>Scenario:</strong></p>
<p>Ihr Chef will eine Inventur der Hardware aller Server und Rechner im Netzwerk. Insbesondere will er folgende Informationen.</p>
<blockquote>
<div><ul class="simple">
<li>Machine manufacturer, model number, and serial number.</li>
<li>BIOS information to determine if updates are required,</li>
<li>OS type</li>
<li>CPU information: Manufacturer, type, speed, and version.</li>
<li>Amount of memory in each server.</li>
<li>Disk information: Size, interface type, and media type.</li>
<li>Network Information: IP settings and MAC address.</li>
</ul>
</div></blockquote>
</div>
<div class="section" id="benutzung-von-wmi">
<span id="index-14"></span><h2>10.9. Benutzung von WMI<a class="headerlink" href="#benutzung-von-wmi" title="Permalink zu dieser Überschrift">¶</a></h2>
<p>WMI ist im Grunde eine Datenbank von Informationen, das auf jeden Windows System vorhanden ist. Über den sog. WMI-Service kann man die jeweils gewünschten Daten abrufen.</p>
<img alt="_images/cimcpu.JPG" src="_images/cimcpu.JPG" />
<p>Von Powershell aus ist die Vorgehensweise relativ einfach: :-)</p>
<div class="highlight-sh"><div class="highlight"><pre>Get-WmiObject -List -Namespace <span class="s2">&quot;root\CIMV2&quot;</span>
</pre></div>
</div>
<img alt="_images/wmi_classes.JPG" src="_images/wmi_classes.JPG" />
<p>Eine etwas kleinere Ausgabe gibt es, wenn man die Ausgabe auf bestimmte Inhalte beschränkt, in unserem Beispiel</p>
<div class="highlight-sh"><div class="highlight"><pre>Get-WmiObject Win32_ComputerSystem | Format-List *
</pre></div>
</div>
<img alt="_images/wmi_win32_suche.png" src="_images/wmi_win32_suche.png" />
<p>Welche Informationen entsprechen den Anforderungen ?</p>
<blockquote>
<div><ul class="simple">
<li>Manufacturer = Manufacturer property.</li>
<li>Model Number = Model property.</li>
<li>Serial Number = Nicht vorhanden; sie muss anderweitig gesucht werden</li>
<li>Gesamtspeicher = TotalPhysicalMemory-Eigenschaft existiert in der Klasse und genügt unseren Ansprüchen.</li>
</ul>
</div></blockquote>
<p><strong>Schritt 1: Machine manufacturer, model number, and serial number</strong></p>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14</pre></div></td><td class="code"><div class="highlight"><pre>     <span class="c">#sets the computer to local</span>
     <span class="nv">$strComputer</span> <span class="o">=</span><span class="s2">&quot;.&quot;</span>

     <span class="c">#Creates a variable called $colItems which contains the WMI Object</span>
     <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_ComputerSystem -Namespace <span class="s2">&quot;root\CIMV2&quot;</span> -ComputerName <span class="nv">$strComputer</span>

     <span class="c">#Use a foreach loop to iterate the $colItems (collection).</span>
     <span class="c">#Store the properties information in the $objItem Variable.</span>
     foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
             <span class="c">#Use the Write-Host cmdlet to output required property information</span>
             Write-Host <span class="s2">&quot;Computer Manufacturer: &quot;</span> <span class="nv">$objItem</span>.Manufacturer
             Write-Host <span class="s2">&quot;Computer Model: &quot;</span> <span class="nv">$objItem</span>.Model
             Write-Host <span class="s2">&quot;Total Memory: &quot;</span> <span class="nv">$objItem</span>.TotalPhysicalMemory <span class="s2">&quot;bytes&quot;</span>
     <span class="o">}</span>
</pre></div>
</td></tr></table></div>
<p><strong>Schritt 2: BIOS-Information</strong></p>
<p>Die entsprechende Klasse im WMI ist Win32_BIOS</p>
<div class="highlight-sh"><div class="highlight"><pre>Get-WmiObject Win32_BIOS | Format-List *
</pre></div>
</div>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10</pre></div></td><td class="code"><div class="highlight"><pre><span class="nv">$strComputer</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span>

     <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_BIOS -Namespace <span class="s2">&quot;root\CIMV2&quot;</span> -computername <span class="nv">$strComputer</span>
     foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span>
     <span class="o">{</span>
             Write-Host <span class="s2">&quot;BIOS:&quot;</span><span class="nv">$objItem</span>.Description
             Write-Host <span class="s2">&quot;Version:&quot;</span><span class="nv">$objItem</span>.SMBIOSBIOSVersion<span class="s2">&quot;.&quot;</span>
             <span class="nv">$objItem</span>.SMBIOSMajorVersion<span class="s2">&quot;.&quot;</span><span class="nv">$objItem</span>.SMBIOSMinorVersion
             Write-Host <span class="s2">&quot;Serial Number:&quot;</span> <span class="nv">$objItem</span>.SerialNumber
     <span class="o">}</span>
</pre></div>
</td></tr></table></div>
<p><strong>Schritt 3: Übrige Informationen</strong></p>
<p><em>OS TYPE:</em></p>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6</pre></div></td><td class="code"><div class="highlight"><pre>     <span class="nv">$strComputer</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span>
     <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_OperatingSystem -Namespace <span class="s2">&quot;root\CIMV2&quot;</span> -Computername <span class="nv">$strComputer</span>

     foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
             Write-Host <span class="s2">&quot;Operating System:&quot;</span> <span class="nv">$objItem</span>.Name
     <span class="o">}</span>
</pre></div>
</td></tr></table></div>
<p><em>CPU Info:</em></p>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7</pre></div></td><td class="code"><div class="highlight"><pre>     <span class="nv">$strComputer</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span>

     <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_Processor -Namespace <span class="s2">&quot;root\CIMV2&quot;</span> -Computername <span class="nv">$strComputer</span>

     foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
             Write-Host <span class="s2">&quot;Processor:&quot;</span> <span class="nv">$objItem</span>.DeviceID <span class="nv">$objItem</span>.Name
     <span class="o">}</span>
</pre></div>
</td></tr></table></div>
<p><em>DISK Info:</em></p>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11</pre></div></td><td class="code"><div class="highlight"><pre>     <span class="nv">$strComputer</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span>

     <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_DiskDrive -Namespace <span class="s2">&quot;root\CIMV2&quot;</span> -ComputerName <span class="nv">$strComputer</span>

     foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span>
     <span class="o">{</span>
             Write-Host <span class="s2">&quot;Disk:&quot;</span> <span class="nv">$objItem</span>.DeviceID
             Write-Host <span class="s2">&quot;Size:&quot;</span> <span class="nv">$objItem</span>.Size <span class="s2">&quot;bytes&quot;</span>
             Write-Host <span class="s2">&quot;Drive Type:&quot;</span> <span class="nv">$objItem</span>.InterfaceType
             Write-Host <span class="s2">&quot;Media Type: &quot;</span> <span class="nv">$objItem</span>.MediaType
     <span class="o">}</span>
</pre></div>
</td></tr></table></div>
<p><em>NETWORK Info:</em></p>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11</pre></div></td><td class="code"><div class="highlight"><pre>     <span class="nv">$strComputer</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span>

     <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace <span class="s2">&quot;root\CIMV2&quot;</span>
     -ComputerName <span class="nv">$strComputer</span> | where<span class="o">{</span><span class="nv">$_</span>.IPEnabled -eq <span class="s2">&quot;True&quot;</span><span class="o">}</span>

     foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
             Write-Host <span class="s2">&quot;DHCP Enabled:&quot;</span> <span class="nv">$objItem</span>.DHCPEnabled
             Write-Host <span class="s2">&quot;Subnet Mask:&quot;</span> <span class="nv">$objItem</span>.IPSubnet
             Write-Host <span class="s2">&quot;Gateway:&quot;</span> <span class="nv">$objItem</span>.DefaultIPGateway
             Write-Host <span class="s2">&quot;MAC Address:&quot;</span> <span class="nv">$ojbItem</span>.MACAddress
     <span class="o">}</span>
</pre></div>
</td></tr></table></div>
<p id="index-15"><strong>Kapseln der Code-Schnipsel in Funktionen</strong></p>
<p>Zur übersichtlicheren Handhabung werden wir die einzelnen Codeelemente in Funktionen kapseln. Alle Funktionen werden in die Datei ServerInventory.ps1 geschrieben.</p>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71</pre></div></td><td class="code"><div class="highlight"><pre>     Function SysInfo
     <span class="o">{</span>
             <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_ComputerSystem <span class="sb">`</span>
             -Namespace <span class="s2">&quot;root\CIMV2&quot;</span> -ComputerName <span class="nv">$strComputer</span> <span class="sb">`</span>

             foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
               Write-Host <span class="s2">&quot;Computer Manufacturer: &quot;</span> <span class="nv">$objItem</span>.Manufacturer
               Write-Host <span class="s2">&quot;Computer Model: &quot;</span> <span class="nv">$objItem</span>.Model
               Write-Host <span class="s2">&quot;Total Memory: &quot;</span> <span class="nv">$objItem</span>.TotalPhysicalMemory <span class="s2">&quot;bytes&quot;</span>
             <span class="o">}</span>
     <span class="o">}</span>

     Function BIOSInfo <span class="o">{</span>

             <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_BIOS -Namespace <span class="s2">&quot;root\CIMV2&quot;</span> <span class="sb">`</span>
             -computername <span class="nv">$strComputer</span> <span class="sb">`</span>
             foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
                     Write-Host <span class="s2">&quot;BIOS:&quot;</span><span class="nv">$objItem</span>.Description
                     Write-Host <span class="s2">&quot;Version:&quot;</span><span class="nv">$objItem</span>.SMBIOSBIOSVersion<span class="s2">&quot;.&quot;</span>
                     <span class="nv">$objItem</span>.SMBIOSMajorVersion<span class="s2">&quot;.&quot;</span><span class="nv">$objItem</span>.SMBIOSMinorVersion
                     Write-Host <span class="s2">&quot;Serial Number:&quot;</span> <span class="nv">$objItem</span>.SerialNumber
             <span class="o">}</span>
     <span class="o">}</span>


     Function OSInfo
     <span class="o">{</span>
             <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_OperatingSystem -Namespace <span class="sb">`</span> <span class="s2">&quot;root\CIMV2&quot;</span> -Computername <span class="nv">$strComputer</span> <span class="sb">`</span>

             foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
                     Write-Host <span class="s2">&quot;Operating System:&quot;</span> <span class="nv">$objItem</span>.Name
             <span class="o">}</span>
     <span class="o">}</span>


     Function CPUInfo
     <span class="o">{</span>
             <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_Processor -Namespace <span class="sb">`</span>
             <span class="s2">&quot;root\CIMV2&quot;</span> -Computername <span class="nv">$strComputer</span>  <span class="sb">`</span>

             foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
                     Write-Host <span class="s2">&quot;Processor:&quot;</span> <span class="nv">$objItem</span>.DeviceID <span class="nv">$objItem</span>.Name
             <span class="o">}</span>
     <span class="o">}</span>


     Function DiskInfo
     <span class="o">{</span>
             <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_DiskDrive -Namespace <span class="sb">`</span> <span class="s2">&quot;root\CIMV2&quot;</span> -ComputerName <span class="nv">$strComputer</span> <span class="sb">`</span>

             foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
                     Write-Host <span class="s2">&quot;Disk:&quot;</span> <span class="nv">$objItem</span>.DeviceID
                     Write-Host <span class="s2">&quot;Size:&quot;</span> <span class="nv">$objItem</span>.Size <span class="s2">&quot;bytes&quot;</span>
                     Write-Host <span class="s2">&quot;Drive Type:&quot;</span> <span class="nv">$objItem</span>.InterfaceType
                     Write-Host <span class="s2">&quot;Media Type: &quot;</span> <span class="nv">$objItem</span>.MediaType
             <span class="o">}</span>
     <span class="o">}</span>


     Function NetworkInfo
     <span class="o">{</span>
             <span class="nv">$colItems</span> <span class="o">=</span> Get-WmiObject Win32_NetworkAdapterConfiguration <span class="sb">`</span> -Namespace <span class="s2">&quot;root\CIMV2&quot;</span> -ComputerName <span class="nv">$strComputer</span> | <span class="sb">`</span> where<span class="o">{</span><span class="nv">$_</span>.IPEnabled -eq <span class="s2">&quot;True&quot;</span><span class="o">}</span>

             foreach<span class="o">(</span><span class="nv">$objItem</span> in <span class="nv">$colItems</span><span class="o">)</span> <span class="o">{</span>
                     Write-Host <span class="s2">&quot;DHCP Enabled:&quot;</span> <span class="nv">$objItem</span>.DHCPEnabled
                     Write-Host <span class="s2">&quot;IP Address:&quot;</span> <span class="nv">$objItem</span>.IPAddress
                     Write-Host <span class="s2">&quot;Subnet Mask:&quot;</span> <span class="nv">$objItem</span>.IPSubnet
                     Write-Host <span class="s2">&quot;Gateway:&quot;</span> <span class="nv">$objItem</span>.DefaultIPGateway
                     Write-Host <span class="s2">&quot;MAC Address:&quot;</span> <span class="nv">$ojbItem</span>.MACAddress
             <span class="o">}</span>
     <span class="o">}</span>
</pre></div>
</td></tr></table></div>
<p>In Powershell müssen die Funktionen vor der ersten Benutzung definiert worden sein. Der Aufruf des Funktionen erfolgt dann einfach <strong>am Ende</strong> des Skriptes.</p>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39</pre></div></td><td class="code"><div class="highlight"><pre>     <span class="c">#*=============================================================</span>
     <span class="c">#* SCRIPT BODY</span>
     <span class="c">#*=============================================================</span>
     <span class="c">#* Connect to computer</span>
     <span class="nv">$strComputer</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span>

     <span class="c">#* Call SysInfo Function</span>
     Write-Host <span class="s2">&quot;Sytem Information&quot;</span>
     SysInfo
     Write-Host

     <span class="c">#* Call BIOSinfo Function</span>
     Write-Host <span class="s2">&quot;System BIOS Information&quot;</span>
     BIOSInfo
     Write-Host

     <span class="c">#* Call OSInfo Function</span>
     Write-Host <span class="s2">&quot;Operating System Information&quot;</span>
     OSInfo
     Write-Host

     <span class="c">#* Call CPUInfo Function</span>
     Write-Host <span class="s2">&quot;Processor Information&quot;</span>
     CPUInfo
     Write-Host

     <span class="c">#* Call DiskInfo Function</span>
     Write-Host <span class="s2">&quot;Disk Information&quot;</span>
     DiskInfo
     Write-Host

     <span class="c">#* Call NetworkInfo Function</span>
     Write-Host <span class="s2">&quot;Network Information&quot;</span>
     NetworkInfo
     Write-Host

     <span class="c">#*=============================================================</span>
     <span class="c">#* END OF SCRIPT: [ServerInventory]</span>
     <span class="c">#*=============================================================</span>
</pre></div>
</td></tr></table></div>
<p><strong>Abfrage eines anderen Computers</strong></p>
<p>Zur Zeit fragt das Skript nur die Daten des eigenen Computers ab. Um auch remote arbeiten zu können, muss die Variable <em>$strComputer</em> ersetzt werden.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$strComputer</span> <span class="o">=</span> Read-Host <span class="s2">&quot;Enter Computer Name&quot;</span>
Write-Host <span class="s2">&quot;Computer:&quot;</span> <span class="nv">$strComputer</span>
</pre></div>
</div>
<p><strong>Optimierungen</strong></p>
<p>Erzeugen Sie eine Textdatei und fügen Sie Computernamen ein. Erweiteren Sie das Skript so, dass es die Textdatei ausliest und den jeweiligen Computer abfragt.</p>
<img alt="_images/computers.JPG" src="_images/computers.JPG" />
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47</pre></div></td><td class="code"><div class="highlight"><pre>     <span class="c">#*===============================================================</span>
     <span class="c">#* SCRIPT BODY</span>
     <span class="c">#*===============================================================</span>
     <span class="c">#* Create and array from C:\MyScripts\Computers.txt</span>

     <span class="nv">$arrComputers</span> <span class="o">=</span> get-Content -Path <span class="s2">&quot;C:\MyScripts\Computers.txt&quot;</span>

     foreach <span class="o">(</span><span class="nv">$strComputer</span> in <span class="nv">$arrComputers</span><span class="o">)</span>
     <span class="o">{</span> <span class="c">#Function Calls go here</span>

             Write-Host <span class="s2">&quot;Computer Name:&quot;</span> <span class="nv">$strComputer</span>
             Write-Host <span class="s2">&quot;======================================&quot;</span>

             <span class="c">#* Call SysInfo Function</span>
             Write-Host <span class="s2">&quot;Sytem Information&quot;</span>
             SysInfo
             Write-Host

             <span class="c">#* Call BIOSinfo Function</span>
             Write-Host <span class="s2">&quot;System BIOS Information&quot;</span>
             BIOSInfo
             Write-Host

             <span class="c">#* Call OSInfo Function</span>
             Write-Host <span class="s2">&quot;Operating System Information&quot;</span>
             OSInfo
             Write-Host

             <span class="c">#* Call CPUInfo Function</span>
             Write-Host <span class="s2">&quot;Processor Information&quot;</span>
             CPUInfo
             Write-Host

             <span class="c">#* Call DiskInfo Function</span>
             Write-Host <span class="s2">&quot;Disk Information&quot;</span>
             DiskInfo
             Write-Host

             <span class="c">#* Call NetworkInfo Function</span>
             Write-Host <span class="s2">&quot;Network Information&quot;</span>
             NetworkInfo
             Write-Host <span class="s2">&quot;End of Report for $strComputer&quot;</span>
             Write-Host <span class="s2">&quot;======================================&quot;</span>
             Write-Host
             Write-Host

     <span class="o">}</span> <span class="c">#End function calls.</span>
</pre></div>
</td></tr></table></div>
<p><strong>Auslesen der Computer aus dem AD</strong></p>
<p>Um sich die Eingabe der Computer in eine Textdatei zu ersparen, kann man auch innerhalb einer Windows-Domäne das ActiveDirectory befragen. Folgendes Skript liefert die Daten der Computernamen innerhalb des AD.</p>
<div class="highlight-sh"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22</pre></div></td><td class="code"><div class="highlight"><pre>     <span class="c">#GetPCNames.ps1</span>

     <span class="nv">$strCategory</span> <span class="o">=</span> <span class="s2">&quot;computer&quot;</span>

     <span class="nv">$objDomain</span> <span class="o">=</span> New-Object System.DirectoryServices.DirectoryEntry

     <span class="nv">$objSearcher</span> <span class="o">=</span> New-Object System.DirectoryServices.DirectorySearcher
     <span class="nv">$objSearcher</span>.SearchRoot <span class="o">=</span> <span class="nv">$objDomain</span>
     <span class="nv">$objSearcher</span>.Filter <span class="o">=</span> <span class="o">(</span><span class="s2">&quot;(objectCategory=$strCategory)&quot;</span><span class="o">)</span>

     <span class="nv">$colProplist</span> <span class="o">=</span> <span class="s2">&quot;name&quot;</span>
     foreach <span class="o">(</span><span class="nv">$i</span> in <span class="nv">$colPropList</span><span class="o">)</span>
     <span class="o">{</span>
             <span class="nv">$objSearcher</span>.PropertiesToLoad.Add<span class="o">(</span><span class="nv">$i</span><span class="o">)</span>
     <span class="o">}</span>

     <span class="nv">$colResults</span> <span class="o">=</span> <span class="nv">$objSearcher</span>.FindAll<span class="o">()</span>

     foreach <span class="o">(</span><span class="nv">$objResult</span> in <span class="nv">$colResults</span><span class="o">)</span>
     <span class="o">{</span>
             <span class="nv">$objComputer</span> <span class="o">=</span> <span class="nv">$objResult</span>.Properties; <span class="nv">$objComputer</span>.name
     <span class="o">}</span>
</pre></div>
</td></tr></table></div>
<p>Speichern Sie das Skript als GetPCNames.ps1, starten Sie es innerhalb ihrer Domäne und speichern Sie das Ergebnis in der Datei Computers.txt</p>
<div class="highlight-sh"><div class="highlight"><pre>.<span class="se">\G</span>etPCNames.ps1 &gt; <span class="s2">&quot;C:\MyScripts\Computers.txt&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="erweiterte-parameter">
<span id="index-16"></span><h2>10.10. Erweiterte Parameter<a class="headerlink" href="#erweiterte-parameter" title="Permalink zu dieser Überschrift">¶</a></h2>
<p><strong>Validierung</strong></p>
<p>Häufig ist es so, dass die Parameter einer Funktion einer Überprüfung bedürften, bevor diese innerhalb einer Funktion benutzt werden. Dies könnte z.B. sein</p>
<ul class="simple">
<li>Ist überhaupt ein Parameter übergeben worden</li>
<li>Hat der Parameter die richtigen Werte</li>
<li></li>
</ul>
<p>In der Regel führt dies dazu, dass der Quellcode innerhalb der Funktion durch Fehlerbehandlungscode erweitert wird, bevor man überhaupt die eigentliche Aufgabe löst.</p>
<p><strong>Bsp:</strong></p>
<p>Im unteren Beispiel soll eine Funktion nur bestimmte Werte für die Parameter akzeptieren sollen.</p>
<ul class="simple">
<li>Name: Tom, Dick, Jane</li>
<li>Alter: Zwischen 21 und 65</li>
<li>Übergebener Dateipfad soll vorhanden sein</li>
</ul>
<p><a class="reference external" href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/15/simplify-your-powershell-script-with-parameter-validation.aspx">http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/15/simplify-your-powershell-script-with-parameter-validation.aspx</a></p>
<div class="highlight-sh"><div class="highlight"><pre>  Function Foo
  <span class="o">{</span>
     Param<span class="o">(</span>
       <span class="o">[</span>String<span class="o">]</span>
       <span class="nv">$Name</span>,
       <span class="o">[</span>Int<span class="o">]</span>
       <span class="nv">$Age</span>,
       <span class="o">[</span>string<span class="o">]</span>
       <span class="nv">$Path</span>
     <span class="o">)</span>
     Process
     <span class="o">{</span>
          If <span class="o">(</span><span class="s2">&quot;Tom&quot;</span>,<span class="s2">&quot;Dick&quot;</span>,<span class="s2">&quot;Jane&quot;</span> -NotContains <span class="nv">$Name</span><span class="o">)</span>
          <span class="o">{</span>
            Throw <span class="s2">&quot;$($Name) is not a valid name! Please use Tom, Dick, Jane&quot;</span>
          <span class="o">}</span>
          If <span class="o">(</span><span class="nv">$age</span> -lt 21 -OR <span class="nv">$age</span> -gt 65<span class="o">)</span>
          <span class="o">{</span>
            Throw <span class="s2">&quot;$($age) is not a between 21-65&quot;</span>
          <span class="o">}</span>
          IF <span class="o">(</span>-NOT <span class="o">(</span>Test-Path <span class="nv">$Path</span> -PathType <span class="s1">&#39;Container&#39;</span><span class="o">))</span>
          <span class="o">{</span>
             Throw <span class="s2">&quot;$($Path) is not a valid folder&quot;</span>
          <span class="o">}</span>
          <span class="c"># All parameters are valid so New-stuff&quot;</span>
          write-host <span class="s2">&quot;New-Foo&quot;</span>
    <span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
<p>Das (noch nicht bekannte) <strong>throw</strong>-Statement gibt eine Fehlermeldung aus und beendet die Funktion.</p>
<p>Diese Vorgehensweise hat mehrere Nachteile:</p>
<ul class="simple">
<li>Ein Großteil des Skriptes ist der Fehlerbehandlung gewidmet.</li>
<li>Die Validierung ist nur so gut wie der sie validierende Quellcode</li>
<li>Die Fehlermeldungen müssen bei Änderungen immer wieder angepasst werden.</li>
</ul>
<p>Aus all diesen Gründen wurden in der Powershell die Möglichkeit der <strong>Parameter-Validierung</strong> eingebaut. Zu den Parametern werden in eckigen Klammern weitere Informationen hinzugefügt, die von der PS zur Laufzeit ausgewertet werden können.</p>
<p>Besser gescripted, sieht der Quellcode wie folgt aus:</p>
<div class="highlight-sh"><div class="highlight"><pre>Function Foo
<span class="o">{</span>
        Param<span class="o">(</span>
        <span class="o">[</span>ValidateSet<span class="o">(</span><span class="s2">&quot;Tom&quot;</span>,<span class="s2">&quot;Dick&quot;</span>,<span class="s2">&quot;Jane&quot;</span><span class="o">)]</span>
        <span class="o">[</span>String<span class="o">]</span>
        <span class="nv">$Name</span>,
        <span class="o">[</span>ValidateRange<span class="o">(</span>21,65<span class="o">)]</span>
        <span class="o">[</span>Int<span class="o">]</span>
        <span class="nv">$Age</span>,
        <span class="o">[</span>ValidateScript<span class="o">({</span>Test-Path <span class="nv">$_</span> -PathType <span class="s1">&#39;Container&#39;</span><span class="o">})]</span>
        <span class="o">[</span>string<span class="o">]</span>
        <span class="nv">$Path</span>
        <span class="o">)</span>
        Process
        <span class="o">{</span>
                write-host <span class="s2">&quot;New-Foo&quot;</span>
        <span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
<p>Der Vorteil dieser Methode ist, dass die Fehlerbehandlung nun implizit von der PS vorgenommen wird, inkl. der Bereitstellung und Ausgabe der Fehlermeldungen.
Insgesamt stehen über 11 Validierungsoptionen zur Verfügung; diese können unter
<a class="reference external" href="http://technet.microsoft.com/en-us/library/dd347600.aspx">http://technet.microsoft.com/en-us/library/dd347600.aspx</a> bzw über <strong>get-help about_functions</strong> abgefragt werden.</p>
<p id="index-17"><strong>Mandatory</strong></p>
<p>Das Mandatory-Argument gibt an, dass ein Parameter erwartet wird. Falls kein Parameter übergeben wird, bricht die Funktion ab.</p>
<div class="highlight-sh"><div class="highlight"><pre>    Function Foo
    <span class="o">{</span>
            Param
            <span class="o">(</span>
                    <span class="o">[</span>parameter<span class="o">(</span><span class="nv">Mandatory</span><span class="o">=</span><span class="nv">$true</span><span class="o">)]</span>
                    <span class="o">[</span>String<span class="o">[]]</span>
                    <span class="nv">$ComputerName</span>
            <span class="o">)</span>
<span class="o">}</span>
</pre></div>
</div>
<p id="index-18">Häufig wird das Manadatory-Argument durch das Help-Message-Argument ergänzt, welches eine Fehlerbeschreibung zum nicht übergebenen Mandatory-Parameter hinzufügt.</p>
<p>Bsp:</p>
<div class="highlight-sh"><div class="highlight"><pre>    Function Foo
    <span class="o">{</span>
            Param
            <span class="o">(</span>
            <span class="o">[</span>parameter<span class="o">(</span><span class="nv">mandatory</span><span class="o">=</span><span class="nv">$true</span>,
                   <span class="nv">HelpMessage</span><span class="o">=</span><span class="s2">&quot;Enter one or more computer names separated by commas.&quot;</span><span class="o">)]</span>
                   <span class="o">[</span>String<span class="o">[]]</span>
                   <span class="nv">$ComputerName</span>
    <span class="o">)</span>
<span class="o">}</span>
</pre></div>
</div>
</div>
<div class="section" id="funktionen-in-profilen">
<h2>10.11. Funktionen in Profilen<a class="headerlink" href="#funktionen-in-profilen" title="Permalink zu dieser Überschrift">¶</a></h2>
<p><a class="reference external" href="http://www.howtogeek.com/126469/how-to-create-a-powershell-profile/">http://www.howtogeek.com/126469/how-to-create-a-powershell-profile/</a></p>
<p>Häufig hat es ein Admin gerne, wenn beim Start der Powershell-Konsole bereits bestimmte Grundfunktionalitäten vorhanden sind. PS kennt hierfür das Konzept der Profildateien, die automatisch beim Start der PS mit geladen werden.</p>
<p>Zunächst sollte geprüft werden, ob es bereits eine Profildatei gibt. Dies kann man durch Ausgabe der Umgebungsvariable $Profile erreichen.</p>
<div class="highlight-sh"><div class="highlight"><pre>Test-Path <span class="nv">$Profile</span>
</pre></div>
</div>
<p>Falls noch keine Datei existiert kann diese mit jedem beliebigem Editor erzeugt werden,ansonsten auch mit</p>
<div class="highlight-sh"><div class="highlight"><pre>New-Item –Path <span class="nv">$Profile</span> –Type File –Force
</pre></div>
</div>
<p>In diese Datei kann jeder Befehl, CommandLet, Modul-Import eingestzt werden. Folgendes Beispiel verdeutlicht die Möglichkeiten.</p>
<div class="highlight-sh"><pre>Set-ExecutionPolicy unrestricted
$ui = (Get-Host).UI.RawUI
$ui.ForegroundColor = "Black"
$ui.BackgroundColor = "Gray"
$ui.WindowTitle = $env:userdomain + "\" + $env:username + " 's Powershell"

function prompt
{
        Write-Host "PS " -nonewline -foregroundcolor Red
        Write-Host $(get-location) "#" -nonewline
        return " "
}

$snapins = Get-PSSnapin -Registered
$snapins | Add-PSSnapin
Get-Module -ListAvailable | Import-Module
Get-PSSnapin | Format-Table -autosize PSVersion, Name
Get-Module | Format-Table -autosize ModuleType, Name
function ff ([string] $glob) { get-childitem -recurse -include $glob }
function osr { shutdown -r -t 5 }
function osh { shutdown -h -t 5 }
function rmd ([string] $glob) { remove-item -recurse -force $glob }
function whoami { (get-content env:\userdomain) + "\" + `
(get-content env:\username); } `

function strip-extension ([string] $filename)
{
        [system.io.path]::getfilenamewithoutextension($filename)
}

function New-PSSecureRemoteSession
{
        param ($sshServerName, $Cred)
        $Session = New-PSSession $sshServerName -UseSSL `
        -Credential $Cred -ConfigurationName C2Remote `

        Enter-PSSession -Session $Session
}

function New-PSRemoteSession
{
        param ($shServerName, $Cred)
        $shSession = New-PSSession $shServerName `
        -Credential $Cred -ConfigurationName C2Remote `

        Enter-PSSession -Session $shSession
}

function prompt
{
        $promptText = "PS&gt;";
        $wi = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $wp = new-object 'System.Security.Principal.WindowsPrincipal' $wi

        if ( $wp.IsInRole("Administrators") -eq 1 )
        {
                $color = "Red"
                $title = "**ADMIN** on " + (hostname);
        }
        else
        {
                $color = "Green"
                $title = hostname;
        }
        write-host $promptText -NoNewLine -ForegroundColor $color
        $host.UI.RawUI.WindowTitle = $title;
        return " "
}

function gotoprofile{set-location C:\Users\paul.cowan\Documents\WindowsPowerShell}

function gotodownloads{set-location C:\Users\paul.cowan\Downloads}
function openscratch{notepad C:\users\paul.cowan\desktop\scratch.txt}
function opencatscratch{cat C:\users\paul.cowan\desktop\scratch.txt}

set-alias notepad "C:\Program Files (x86)\Notepad++\notepad++.exe"
set-alias zip "C:\Program Files\7-Zip\7z.exe"
set-alias grep select-string
set-alias ssh New-PSSecureRemoteSession
set-alias sh New-PSRemoteSession
set-alias grep select-string
set-alias ssh New-PSSecureRemoteSession
set-alias sh New-PSRemoteSession
set-alias tr gototrunk
set-alias pr gotoprojects
set-alias profile gotoprofile
set-alias build gotobuild
set-alias downloads gotodownloads
set-alias nc gotoncontinuity2
set-alias lead gotolead
set-alias live gotocurrent
set-alias live_build gotocurrentbuild
set-alias scratch openscratch
set-alias catscratch opencatscratch
set-alias ie "C:\Program Files\Internet Explorer\iexplore.exe"
set-alias c2 gotoc2
set-alias c2web "C:\projects\continuity2\ncontinuity2.web.sln"</pre>
</div>
</div>
<div class="section" id="urls">
<h2>10.12. Urls<a class="headerlink" href="#urls" title="Permalink zu dieser Überschrift">¶</a></h2>
<p><a class="reference external" href="http://technet.microsoft.com/en-us/library/dd347600.aspx">http://technet.microsoft.com/en-us/library/dd347600.aspx</a></p>
<p><a class="reference external" href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/22/use-powershell-to-make-mandatory-parameters.aspx">http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/22/use-powershell-to-make-mandatory-parameters.aspx</a></p>
<p><a class="reference external" href="http://www.simple-talk.com/dotnet/.net-tools/down-the-rabbit-hole--a-study-in-powershell-pipelines,-functions,-and-parameters/">http://www.simple-talk.com/dotnet/.net-tools/down-the-rabbit-hole&#8211;a-study-in-powershell-pipelines,-functions,-and-parameters/</a></p>
<p><a class="reference external" href="http://cleancode.sourceforge.net/wwwdoc/articles.html">http://cleancode.sourceforge.net/wwwdoc/articles.html</a></p>
<p><a class="reference external" href="http://powershell.isdecisions.com/">http://powershell.isdecisions.com/</a></p>
<p><a class="reference external" href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx">http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/21/understanding-the-six-powershell-profiles.aspx</a></p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="Allgemeiner Index"
             >Index</a></li>
        <li class="right" >
          <a href="powershell_pipeline.html" title="11. Pipeline"
             >weiter</a> |</li>
        <li class="right" >
          <a href="powershell_struktogramm.html" title="9. Diagramme der strukturierten Programmierung"
             >zurück</a> |</li>
        <li><a href="index.html">PS4SYS</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2010, STE.
      Mit <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1 erstellt.
    </div>
  </body>
</html>